package com.example.baiguangsystem.config;

import com.example.baiguangsystem.interceptor.LoginCheckInterceptor;
import com.example.baiguangsystem.interceptor.RootUserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器注册类
 *
 * @Author: 27641
 * @ProjectName: BaiGuangSystem
 * @Date: 2022/02/06/19:59
 * @noinspection SpellCheckingInspection
 */
/*@Configuration*/
public class InterceptorRegister implements WebMvcConfigurer {

    /**
     * 自定义拦截器
     */
    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;
    @Autowired
    private RootUserInterceptor rootUserInterceptor;

    /**
     * 设置拦截规则
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*登录权限拦截*/
        registry.addInterceptor(loginCheckInterceptor)
                /*拦截所有路径*/
                .addPathPatterns("/**")
                /*放行路径*/
                .excludePathPatterns("/**/login")
                .excludePathPatterns("/**/error");
        /*超级用户权限拦截*/
        registry.addInterceptor(rootUserInterceptor)
                .addPathPatterns("/user/findAllUser")
                .addPathPatterns("/user/findAllUserByLimit");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
